import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import { createHtmlPlugin } from 'vite-plugin-html'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'  //便于使用组件名
import { resolve } from 'path'
import autoprefixer from 'autoprefixer'

const name = '标准模板'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0',
    proxy: {
      '^/api1': {
        // target: 'http://192.168.8.181:21030',
        target: 'http://192.168.8.181:54322',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api1/, '')
      },
      '^/api2': {
        target: 'http://192.168.8.181:5000',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api2/, '')
      },
      '^/jjy': {
        target: 'http://192.168.1.101:5100',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/jjy/, '')
      },
      '^/mqtt': {
        // target: 'http://192.168.1.101:8083/mqtt',
        target: 'http://192.168.1.101:1888/mqtt',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/mqtt/, '')
      }
    }
  },
  css: {
    postcss: {
      plugins: [ autoprefixer({}) ]
    }
    // preprocessorOptions: {
    //   scss: {
    //     additionalData: `@import "@/styles/theme.scss";`
    //   }
    // }
  },
  plugins: [
    vue(),
    vueSetupExtend(),
    eslintPlugin({
      include: [ 'src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue' ]
    }),
    createHtmlPlugin({
      inject: {
        data: {
          title: name
        }
      }
    })
  ],
  build: {
    chunkSizeWarningLimit: 8000,
    target: 'es2015',
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: false,
        drop_debugger: true
      }
    },
    rollupOptions: {
      output: {
        manualChunks: {
          vue: [ 'vue' ]
        }
      }
    }
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src') // 路径别名
    },
    extensions: [ '.js', '.json', '.ts' ]
  }
})
